package com.hotel.config.rabbitmq.customer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.common.utils.LocalDateTimeToTimeStamp;
import com.hotel.config.websocket.WebSocketProcess;
import com.hotel.websocketsystem.mapper.CustomerServiceMessageMapper;
import com.hotel.websocketsystem.pojo.CustomerServiceMessage;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;

import static com.hotel.config.rabbitmq.config.TMC_WS_Delay_DirectConfig.TMC_DELAY_QUEUE;

@Component
public class TMC_WS_Customer {
    @Resource
    private CustomerServiceMessageMapper serviceMessageMapper;

    @Resource
    private WebSocketProcess webSocketProcess;

    //websocket  客服聊天
    @RabbitHandler
    @RabbitListener(queues = TMC_DELAY_QUEUE)
    public void deleteMsg(CustomerServiceMessage serviceMessage) throws Exception {
        LambdaQueryWrapper<CustomerServiceMessage> queryWrapper=new LambdaQueryWrapper<>();
        //  querywrapper 提供的是 查询时间是字符串
//        将localdatetiem 格式转换成 字符串类型
        String time = LocalDateTimeToTimeStamp.getLocalDateTimeStr(serviceMessage.getOverTime());
        queryWrapper.eq(CustomerServiceMessage::getOverTime,time);
        int delete = serviceMessageMapper.delete(queryWrapper);
        if (delete > 0) webSocketProcess.sendMessage(serviceMessage.getUserAdmin01(),"消息已过期");
    }
}
